package m.jclecai.com.dialog;

import android.content.Context;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import m.jclecai.com.R;
import m.jclecai.com.adapter.LuckyGigtAdapter;
import m.jclecai.com.bean.LuckyWalkBean;
import m.jclecai.com.listener.Callback;
import m.jclecai.com.utils.http.responseBody.LuckyWalkBody;

/**
 * Created by ZD on 2017/7/4.
 */

public class MyGiftDialog extends BaseDialog {

    @BindView(R.id.iv_close)
    ImageView ivClose;
    @BindView(R.id.lvBody)
    ListView lvBody;
    @BindView(R.id.tvUp)
    TextView tvUp;
    @BindView(R.id.tvPage)
    TextView tvPage;
    @BindView(R.id.tvNext)
    TextView tvNext;
    LuckyWalkBody body;
    Callback callback;
    LuckyGigtAdapter adapter;
    private List<LuckyWalkBean> records;
    int mPage = 1;
    int mPages = 1;

    public MyGiftDialog(Context context) {
        super(context);
        initView();
    }

    void initView() {
        setContentView(R.layout.dialog_my_gift);
        records = new ArrayList<>();
        adapter = new LuckyGigtAdapter(records, getContext());
        lvBody.setAdapter(adapter);
    }

    @OnClick(R.id.iv_close)
    void close() {
        dismiss();
    }

    @OnClick(R.id.tvUp)
    void up() {
        if (mPage <= 1)
            return;
        if (callback != null)
            callback.callback(-1);
    }

    @OnClick(R.id.tvNext)
    void next() {
        if (mPage >= mPages)
            return;
        if (callback != null)
            callback.callback(1);
    }

    public void setBody(int page,LuckyWalkBody body) {
        this.body = body;
        this.mPage = page;
        mPages = body.getPages();
        updateTxt();
    }

    public void setCallback(Callback callback) {
        this.callback = callback;
    }

    void updateTxt() {
        tvPage.setText(mPage + "/" + mPages);
        records.clear();
        records.addAll(body.getRecords());
        adapter.notifyDataSetChanged();
    }
}
